# coding: UTF-8
# Filename : branch_data_model.py
# Company : imedia
# Author : rose
# -*-coding:utf-8 -*-


'''

def get_star_row(size, pagenum):
    if size == 0 or pagenum == 0: return 0
    return size*(int(pagenum) -1)

a = '2'
b = '5'
c = int(a)
d = int(b)
print get_star_row(c,d)

import re
#验证是否为数字
def is_num(str):
    return regex('^\d+$',str)
#做正则验证
def regex(regex, str):
    pattern = re.compile(regex)  
    match = pattern.match(str.strip())  
    if match:  
        return True
    else:
        return False

    
print is_num('  123  ')
str = 'abcdefghaha123'
#去最后八位数
print str[0:2]

a = ['aa', 'bb']
b = ['cc', 'dd']
c = ('aa', 'bb')
d = ('cc', 'dd')
print a+b
print d

import os
str = os.popen("dir").read()
a = str.split("\n")
for b in a:
   print b
   
import random   
#随即生成n位密钥
def get_random_str(n = 6):
    num_arrays = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    rst = ''
    for i in range(0, n):
        num = random.randint(0,9)
        rst += str(num_arrays[num])
    return rst

print get_random_str()


import cPickle as p
import utils,time
#存储对象到文件
def store_obj(obj):
    switchlistfile = 'info.data'
    f = file(switchlistfile, 'w')
    p.dump(obj, f)
    f.close()
#获得存储文件中数据
def get_obj():
    switchlistfile = 'info.data'
    f = file(switchlistfile)
    obj = p.load(f)
    f.close()
    return obj

#检查获取密码时间
def check_is_get_pwd(mobile):
    flag = True
    #时间间隔120秒
    time_limit_allowed = 120
    obj = get_obj()
    now = int(time.time())
    if isinstance(obj, dict):
        if obj.has_key(mobile):
            last_time = obj[mobile]
            time_limit =  now - last_time
            if time_limit < time_limit_allowed:
                flag = False
                print obj
                print flag
            else:
                obj[mobile] = now
                store_obj(obj)
                print '-----------------'
                print obj
        else:
            obj[mobile] = now
            store_obj(obj)
    return flag
            
   
check_is_get_pwd('13500999900')
switchlistfile = 'info.data'
f = file(switchlistfile, 'w')
p.dump({}, f)
f.close()
print get_obj()
'''


import os, const
def image_path(img_str, ratio = '320x480', is_thumb = False):
    thumb = 'thumb'
    parent_dir = '/upload'
    if img_str == None: return ""
    if ratio == None or ratio.strip() == '': ratio = '320x480'
    i = 0
    image = ''
    img_str = str(img_str)
    for img in img_str.split(';'):
        if len(img.strip()) > 0:
            sp = '' if i == 0 else ';'
            img = img.replace(parent_dir, '')
            if is_thumb:
                image += sp + const.domain + parent_dir + os.sep + ratio + os.sep + thumb + img
            else:    
                image += sp + const.domain + parent_dir + os.sep + ratio + img
            i += 1
    return image
    

print image_path('/upload/11.jpg;/upload/22.jpg', '200x180')
    